home *** CD-ROM | disk | FTP | other *** search
- ////////////////////////////////////////////////////////////////
- // File - USERMODE.C
- //
- // This is a sample for opening a kernel plugin, and performing a
- // function call to it.
- //
- ////////////////////////////////////////////////////////////////
-
- #include <stdio.h>
- #include "../../../include/windrvr.h"
- #include "../../../include/windrvr_int_thread.h"
- #include "../kptest_com.h"
-
- static char line[256];
-
- void DoKernelPlugInCall(HANDLE hWD, DWORD hKernelPlugIn)
- {
- WD_KERNEL_PLUGIN_CALL kpCall;
- KPTEST_VERSION kptestVer;
-
- BZERO (kpCall);
- kpCall.hKernelPlugIn = hKernelPlugIn;
- kpCall.dwMessage = KPTEST_MSG_VERSION;
- kpCall.pData = &kptestVer;
- // this will call KP_Call() callback in the kernel
- WD_KernelPlugInCall(hWD, &kpCall);
- printf ("KPTest version: %s\n",kptestVer.cVer);
- }
-
- WD_INTERRUPT Intrp;
-
- // KP_IntAtIrql() callback in the kernel will be called when an interrupt
- // occurs.
- // if KP_IntAtIrql() returns TRUE, then KP_IntAtDpc() callback in the kernel
- // will be called.
- // if KP_IntAtDpc() returns a value of 1 or greater, then interrupt_handler(),
- // that is waiting on WD_IntWait() will be called.
- VOID interrupt_handler (PVOID pData)
- {
- printf ("Got interrupt %d\n", Intrp.dwCounter);
- }
-
- void DoKernelPlugInInterrupt(HANDLE hWD, DWORD hKernelPlugIn)
- {
- WD_CARD_REGISTER cardReg;
- HANDLE thread_handle;
-
- BZERO(cardReg);
- printf ("Enter the interrupt number to install (X to cancel):");
- fgets (line, sizeof(line), stdin);
- sscanf(line, "%d", &cardReg.Card.Item[0].I.Int.dwInterrupt);
- if (toupper(line[0])=='X' || cardReg.Card.Item[0].I.Int.dwInterrupt==0)
- {
- printf ("install interrupt canceled\n");
- return;
- }
- cardReg.Card.Item[0].item = ITEM_INTERRUPT;
- cardReg.Card.dwItems = 1;
- WD_CardRegister(hWD, &cardReg);
- if (!cardReg.hCard)
- {
- printf ("Failed installing interrupt\n");
- return;
- }
-
- BZERO(Intrp);
- Intrp.hInterrupt = cardReg.Card.Item[0].I.Int.hInterrupt;
- // tell WinDriver that this interrupt will be handled by a
- // Kernel PlugIn.
- Intrp.kpCall.hKernelPlugIn = hKernelPlugIn;
- // this calls WD_IntEnable() and creates an interrupt handler thread
- // also it call KP_IntEnable() callback in the kernel
- if (!InterruptThreadEnable(&thread_handle, hWD, &Intrp, interrupt_handler, NULL))
- {
- printf ("failed enabling interrupt\n");
- }
- else
- {
- // call your driver code here
- printf ("Press Enter to uninstall interrupt\n");
- fgets(line, sizeof(line), stdin);
-
- // this calls WD_IntDisable()
- // also it call KP_IntDisable() callback in the kernel
- InterruptThreadDisable(thread_handle);
- }
- WD_CardUnregister(hWD, &cardReg);
- }
-
- int main( int argc, char *argv[] )
- {
- HANDLE hWD = INVALID_HANDLE_VALUE;
- WD_VERSION ver;
- WD_KERNEL_PLUGIN kernelPlugIn;
-
- hWD = WD_Open();
- if (hWD==INVALID_HANDLE_VALUE)
- {
- printf ("error opening WINDRVR\n");
- return EXIT_FAILURE;
- }
-
- BZERO(ver);
- WD_Version (hWD, &ver);
- printf (WD_PROD_NAME " version - %s\n", ver.cVer);
- if (ver.dwVer<WD_VER)
- {
- printf ("error incorrect WINDRVR version. needs ver %d\n",WD_VER);
- WD_Close(hWD);
- return EXIT_FAILURE;
- }
-
- BZERO (kernelPlugIn);
- kernelPlugIn.pcDriverName = "KPTEST"; // this will search for KPTEST.VXD or KPTEST.SYS
- // VXD: for Windows 95/98/ME: under \WINDOWS\SYSTEM\VMM32
- // SYS: for Windows NT/2K: under \WINDOWS\SYSTEM32\DRIVERS
-
- // If you need to load the driver from an absolute path, instead of the above paths, you
- // should specify as follows:
- // for VXD under 95/98/ME
- // kernelPlugIn.pcDriverPath = "C:\\WINDRVR\\KERPLUG\\KPTEST\\KERMODE\\WIN95\\KPTEST.VXD";
- // for SYS under NT/2K
- // kernelPlugIn.pcDriverPath = "C:\\WINDRVR\\KERPLUG\\KPTEST\\KERMODE\\WINNT\\KPTEST.SYS";
- //
- // NOTE:
- // The Windows 98 kernel does not accept long file names. So make sure that the path
- // specified above does not contain any file or directory name that does not follow
- // the MSDOS 8.3 filename limitation. For example "WINDRIVER" is not acceptable.
- // If you indeed have a name longer than 8 characters, then please find its legacy
- // MSDOS name. For example, WINDRIVER would probably map to WINDRV~1. You can use
- // the Windows 98 MSDOS command prompt to find this - the DIR listing will show
- // both the long name as well as the MSDOS name
-
- // this will call KP_Open() callback in the kernel
- WD_KernelPlugInOpen(hWD, &kernelPlugIn);
- if (!kernelPlugIn.hKernelPlugIn)
- {
- printf ("There was an error loading driver %s\n",kernelPlugIn.pcDriverName);
- printf ("\n");
- printf ("If you are using Win95/98:\n");
- printf (" Make sure you copied KPTEST.VXD to c:\\win95\\system\\vmm32.\n");
- printf ("\n");
- printf ("If you are using WinNT:\n");
- printf (" Make sure you copied KPTEST.SYS to c:\\winnt\\system32\\drivers.\n");
- printf (" Run: \\windriver\\util\\WDREG -name KPTEST install\n");
- return EXIT_FAILURE;
- }
- printf("Kernel Plugin opened\n");
-
- DoKernelPlugInCall(hWD, kernelPlugIn.hKernelPlugIn);
- DoKernelPlugInInterrupt(hWD, kernelPlugIn.hKernelPlugIn);
-
- // this will call KP_Close() callback in the kernel
- WD_KernelPlugInClose(hWD, &kernelPlugIn);
- WD_Close(hWD);
- return EXIT_SUCCESS;
- }
-